package com.liziba.reflect;

import java.lang.reflect.Constructor;

/**
 * <p>
 *
 * </p>
 *
 * @Author: Liziba
 * @Date: 2021/4/25 23:29
 */
public class TestReflectBreakSingleInstance {

    public static void main(String[] args) {

        SingletonFactory instance2 = null;
        SingletonFactory instance1 = SingletonFactory.getInstance();
        System.out.println(instance1);

        Class<?> clazz = null;
        try {
            clazz = Class.forName("com.liziba.reflect.SingletonFactory");
            Constructor<?> constructor = clazz.getDeclaredConstructor(null);
            constructor.setAccessible(true);
            instance2 = (SingletonFactory)constructor.newInstance();
            System.out.println(instance2);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(instance1 == instance2);

    }

}
